package com.spark.core.examples

import org.apache.spark.broadcast.Broadcast
import org.apache.spark.rdd.RDD
import org.apache.spark.{SparkConf, SparkContext}

object BroadCastTest {

  def main(args: Array[String]): Unit = {
    val conf = new SparkConf()
    conf.setMaster("local")
    conf.setAppName("broadCast")
    val sc = new SparkContext(conf)
    sc.setLogLevel("error")

    val list = List[String]("zhangsan", "tianqi")
    // val broadList: Broadcast[List[String]] = sc.broadcast(list)

    val broadList: Broadcast[List[String]] = sc.broadcast(list)

    val nameRdd: RDD[String] = sc.parallelize(List[String]("zhangsan",
      "lisi",
      "wangwu",
      "zhaoliu",
      "tianqi"))

    val result: RDD[String] = nameRdd.filter(name => {
      broadList.value.contains(name)
    })

    result.foreach(println)
  }

}
